/**
 * detail info
 * @author    Zheng Kejun
 * @copyright (c) 2015, by Zheng Kejun
 * @version   0.1
  */

 //Ext.MessageBox.buttonText.yes="确定";
//Ext.MessageBox.buttonText.no="取消";


var companel = new CompositePanel(nid);
Ext.onReady(function(){
      Ext.QuickTips.init();
      companel.display();
	  companel.dataConfig.baseParams['filter.'+companel.dataConfig.idProperty]=Math.abs(sid);
  	  companel.refresh();
 });

companel.initBefore=function(){
	this.loadFormFields();
  	this.gridConfig=false;
	this.dataConfig.autoLoad=false;
  	this.dataConfig.listeners={'load':loadValue};
	this.formConfig.title=null;//'信息';
	this.formConfig.collapsible=false;
    this.formConfig.buttons=this.getButtons(['doCancel','doReload']);
    this.formConfig.buttonAlign="left";
	this.formConfig.trackResetOnLoad=true;
  };
  
 companel.doCancel=function(){
	  window.parent.closeTab();  
  };
  
companel.loadFormFields=function(){
	var flds=this.formConfig.items=[];
	var datum=this.getColsConfig().datum;
	for(var i=0;i<datum.length;i++){
		var fld = this.getFieldByMeta(datum[i]);
		if( fld ){ flds.push(fld); }
	}
};


//gird title's column config  by data type 
companel.getFieldByMeta=function(meta){
	var attr = storeHelper.getAttrs(meta['SID']);
	if(attr.hidden){return null;}// or return hidden field?
	Ext.applyIf(attr,meta);
	attr.readOnly=true;
	var fld= FormEditorUtil.get(meta['DTYPE'],attr);
	if( fld.fieldLabel && fld.allowBlank===false ){
		fld.fieldLabel += '<font color=red>*</font>';
	}
	return fld;
};

	
function loadValue(store,recs,opts){
	if(recs.length==0){
		alert("记录不存在");
		return;
	}
	var form = companel.formPanel.getForm();
	var cols = companel.dataConfig.fields;
	for(var i=0;i<cols.length;i++){
		var fname = cols[i].name||cols[i];
		var val = recs[0].get(fname);
		var fld = form.findField('dataTO.map.'+fname);
		if( fld ){
			fld.setValue(val);
			fld.originalValue=fld.getValue();
		}
		var cbo = form.findField('combo.'+fname);
		if( cbo ){
			cbo.setValue(val);
			cbo.originalValue=cbo.getValue();
		}
	}
}
